﻿using System.Web.Mvc;
using CandidateManager.Controllers;
using WI.CandidateManager.Business.Objects;
using candidate = WI.CandidateManager.Common.Data.Entities.Candidate;

namespace CandidateManager.Areas.Admin.Controllers
{
    public class CandidatesController : AutorizeBaseController
    {
        private readonly CandidateBO candidateBO = new CandidateBO();

        // GET: /Admin/Candidates/List
        public ActionResult Index()
        {
            return RedirectToAction("List");
        }

        // GET: /Admin/Candidates/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: /Admin/Candidates/Create
        [HttpPost]
        public ActionResult Create(candidate candidate)
        {
            candidateBO.CreateCandidate(candidate);

            return RedirectToAction("List");
        }

        // GET: /Admin/Candidates/List
        public ActionResult List()
        {
            return View(candidateBO.GetCandidates());
        }

        // GET: /Admin/Candidates/Update/ID
        public ActionResult Update(long id)
        {
            return View(candidateBO.GetCandidates(id));
        }

        // POST: /Admin/Candidates/Update
        [HttpPost]
        public ActionResult Update(candidate candidate)
        {
            candidateBO.UpdateCandidate(candidate);

            return RedirectToAction("List");
        }

        // GET: /Admin/Candidates/Delete/ID
        public ActionResult Delete(long id)
        {
            candidateBO.DeleteRecord(id);

            return RedirectToAction("List");
        }
    }
}
